package services

import (
	context "context"
	"fmt"
)

type ProdService struct{}

func (*ProdService) GetProductStock(ctx context.Context, req *ProdRequest) (*ProdResponse, error) {
	fmt.Println("server receive request...", req.ProdId)
	//增加枚举类型参数使用
	if req.ProdArea == ProdAreas_A {
		return &ProdResponse{
			ProdStock: 101,
		}, nil
	} else if req.ProdArea == ProdAreas_B {
		return &ProdResponse{
			ProdStock: 102,
		}, nil
	} else if req.ProdArea == ProdAreas_C {
		return &ProdResponse{
			ProdStock: 103,
		}, nil
	}

	return &ProdResponse{
		ProdStock: 0,
	}, nil

}

func (*ProdService) GetProductStocks(ctx context.Context, req *QuerySize) (*ProdResponseList, error) {
	size := req.GetSize()
	//切片(列表)
	res := make([]*ProdResponse, 0)
	var i int32 = 0
	for i = 0; i < size; i++ {
		res = append(res, &ProdResponse{ProdStock: i + 1})
	}
	fmt.Println("size=", size, "res=", res)
	return &ProdResponseList{Prodres: res}, nil
}

func (*ProdService) GetProductInfo(ctx context.Context, req *ProdRequest) (*ProdModel, error) {
	prodId := req.ProdId
	fmt.Println("server receive request...", req.ProdId)
	return &ProdModel{ProdId: prodId, ProdName: "李锦记薄盐生抽", ProdPrice: 9.8}, nil
}

//接口通过命令会自动生成的方法, 不需要可以不实现, 并从 Prod_grpc.pb.go 中的 ProductServiceServer 中删除
func (*ProdService) mustEmbedUnimplementedProductServiceServer() {

}
